<?php

namespace App\Http\Controllers\staff;

use Illuminate\Http\Request;
use DB;
use Cookie;
use Hash;
use App\Http\Controllers\Controller;
//模型
use App\Models\Role;

class LoginController extends Controller
{
    //员工登录页面
    public function getIndex(){
        return view('staff.login.index');
    }

    //员工登录处理
    public function postLogon(Request $request){
        //获取登录信息
        $info = $request -> except("_token");
        //查询member表
        $res = DB::table('staff') -> where(['phone'=>$info['phone']]) -> select('id','name','phone','email','pwd','staff_role_id','agent_id') -> first();
        if($res && Hash::check($info['pwd'],$res['pwd'])){
            //将登录信息存入cookie
            Cookie::queue('staffInfo',$res,0);
            return redirect('/staff/layout/index');
        }else{
            return back()->withInput()->with('msg','登录失败！');
        }
    }
}